<html>
<head>
    <meta charset="UTF-8">
    <link href="./static/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="./static/assets/global/css/components.css" rel="stylesheet" type="text/css"/>
    <link href="./static/assets/admin/pages/css/login.css" rel="stylesheet" type="text/css"/>
    <script src="./static/assets/global/plugins/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="./js/common.js" type="text/javascript"></script>
</head>

<body class="login">
<div class="content">
    <h3 class="form-title">添加活动</h3>
    <div class="form-group">
        <label class="control-label">活动名称</label>
        <div>
            <input class="form-control" type="text" name="activityName" id="activityName"/>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label">开始时间</label>
        <div>
            <input class="form-control" type="datetime-local" name="startTime" id="startTime"/>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label">结束时间</label>
        <div>
            <input class="form-control" type="datetime-local" name="endTime" id="endTime"/>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label">活动描述</label>
        <div>
            <input class="form-control" type="text" name="activityDesc" id="activityDesc"/>
        </div>
    </div>
    <div class="form-actions">
        <button class="btn blue" id="create" type="submit">
            提交
        </button>
    </div>
</div>


</body>


<script>

    jQuery(document).ready(function () {

        //绑定otp的click时间用于向后端发送获取手机验证码的请求
        $("#create").on("click", function () {
            var activityName = $("#activityName").val();
            var startTime = $("#startTime").val();
            var endTime = $("#endTime").val();
            var activityDesc = $("#activityDesc").val();

            if (activityName == null || activityName == "") {
                alert("活动名称不能为空");
                return false;
            }
            if (startTime == null || startTime == "") {
                alert("开始时间不能为空");
                return false;
            }
            startTime = dateFormat(startTime)
            if (endTime == null || endTime == "") {
                alert("结束时间不能为空");
                return false;
            }
            endTime = dateFormat(endTime)
            if (activityDesc == null || activityDesc == "") {
                alert("活动描述不能为空");
                return false;
            }

            $.ajax({
                type: "POST",
                headers:{
                    "access-token": get(common_localstorage_key)
                },
                contentType: "application/x-www-form-urlencoded",
                url: "http://"+g_host+"/activity/saveSeckillActivity",
                data: {
                    "activityName": activityName,
                    "startTime": startTime,
                    "endTime": endTime,
                    "activityDesc": activityDesc
                },
                xhrFields: {withCredentials: true},
                success: function (data) {
                    if (data.code == "1001") {
                        alert("创建成功");
                        window.location.href="activity_list.html";
                    } else if (data.code == 2012){
                        alert("请登录后操作")
                        window.location.href = "login.html";
                    }
                    else {
                        alert("创建失败");
                    }
                },
                error: function (data) {
                    alert("创建失败");
                }
            });
            return false;
        });


    });


</script>


</html>